<%@ page language="java" contentType="text/html; charset=windows-1255"
    pageEncoding="windows-1255"%>
<script src="validate.js" type="text/javascript"></script>

	<div id="content" class="post">
		<h1 class="title">Welcome to Course Schedule Planner</h1>
         <p>Students may use Course Schedule Planner to build, compare, review, and register schedules for available semesters. 
            Long term planning, course catalog search, improved calendar view, advanced filtering,
            wish list and WebReg integration are just a few features that will make planning a schedule easier and faster than ever.
        </p>
 	 </div>
 	 
  	 <div id="sidebar">
		<ul>
      		<li>
        	<h2>Already a user?</h2>
        	<form action="Login" method="post" onsubmit="return loginValidation(this);">
  			<table>
			<tr>
			<td>Username:</td>
			<td><input type="text" name="username" /></td>
			</tr>
			<tr>
			<td>Password:</td>
			<td><input type="password" name="password" /></td>
			</tr>
  			</table>
			<h3><input type="submit" value="Login"></input></h3>
			</form>
      		</li>
      		<li>
        	<h2>No? Create an account!</h2>
        	<center>
        	<table>
			<tr>
			<td>
 			<button id="registrationButton">Click Here</button>
			</td>
			</tr>
  			</table>
        	</center>
      		</li> 
    	</ul>
    </div>

<%  //incase login faild show an alert.
	String LastResultFailed = (String)request.getSession().getAttribute("LastResultFailed");
	if (LastResultFailed != null) { %>
		<script type="text/javascript"> 
		alert("Login Failed!\n"+
		      "Please check your username and password"); 
		</script>
<% 		request.getSession().removeAttribute("LastResultFailed");
		}%>
		
<% //incase registration faild:
	String usernameExist = (String)request.getSession().getAttribute("usernameExist");
	if (usernameExist != null) { %>
		<script type="text/javascript"> 
			$('#page').load("registration.jsp",function(response, status, xhr) {
				  if (status == "error") {
					    var msg = "Sorry but there was an error: ";
					    $("#page").html("<br />" +"<h1>" + msg + xhr.status + " " + xhr.statusText +"</h1>" );
					  }
					});
			alert("Registration Failed!\n"  +
				  "Username already exist!\n" +
				  "Please choose another Username"); 
		</script>
<% 	request.getSession().removeAttribute("usernameExist");
		} else {
			String wrongCode = (String)request.getSession().getAttribute("wrongCode");
			if (wrongCode != null) { %>
				<script type="text/javascript"> 
					$('#page').load("registration.jsp",function(response, status, xhr) {
						  if (status == "error") {
							    var msg = "Sorry but there was an error: ";
							    $("#page").html("<br />" +"<h1>" + msg + xhr.status + " " + xhr.statusText +"</h1>" );
							  }
							});
					alert("Registration Failed!\n"  +
						  "wrong administrator code!");
					
				</script>
 <%     	request.getSession().removeAttribute("wrongCode");
			}
		} %>

